import requests
import json

spaceID = "mt0pmhki5db7"
accessToken = "8c7dbd270cb98e83f9d8d57fb8a2ab7bac9d7501905fb013c69995ebf1b2a719"

endpoint = f"https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3"
headers = {"Authorization": f"Bearer {accessToken}"}

query = """
{
  tokens(where:{symbol_contains:"ETH", totalValueLockedUSD_gt:1000000}) {
    name
    id
    symbol
    volumeUSD
    totalValueLockedUSD
  }
}
"""


query_tokens = """
{
  tokens(where:{totalValueLockedUSD_gt:1000000}) {
    name
    id
    symbol
    volumeUSD
  }
}
"""


query_pools = """
{
    pools(first:1000, where:{liquidity_gt:0}) {
        id
        token0 {
        id
        symbol
        }
        token1 {
        id
        symbol
        }
        feeTier
        liquidity
    }
}
"""

# By default return only first 100 data
r = requests.post(endpoint, json={"query": query}, headers=headers)
if r.status_code == 200:
    print(json.dumps(r.json(), indent=2))
    print(f'total_token number : {len(r.json()["data"]["tokens"])}')
else:
    raise Exception(f"Query failed to run with a {r.status_code}.")